package com.luguokong.pet_rescue.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.luguokong.pet_rescue.pojo.Pet;
import com.luguokong.pet_rescue.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/pet")
public class PetCtrl {
    @Autowired
    private PetService petService;

    @GetMapping("/getAllPet")
    public List<Pet> getAllPet(){
        List<Pet> petList = petService.selectPetAll();
//        System.out.println(petList.size());
        return petList;
    }

    @GetMapping("/getByPage")
    public List<Pet> selectPetAllByPageNumByPageSize(int pageNum, int pageSize){
        List<Pet> petList = petService.selectPetAllByPageNumByPageSize((pageNum-1)*pageSize, pageSize);
        return petList;
    }

    @GetMapping("/getDataCount")
    public int selectDataCount(){
        int count = petService.selectDataCount();
        return count;
    }

    @PostMapping("/updateByPetId")
    public int updatePetById(@RequestBody Pet pet){
//        System.out.println(pet);
        int i = petService.updatePetById(pet);
        return i;
    }

    @GetMapping("/deletePetById")
    public int deletePetById(Integer petId){
        int i = petService.deletePetById(petId);
        return i;
    }

    @PostMapping("/insertPet")
    public int insertPet(@RequestBody Pet pet){
        int i = petService.insertPet(pet);
        return i;
    }

}
